package edu.cuit.avatar;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/9 10:54
 */
public class StringTest {
    public static void main(String[] args) {
        String s1 = "a";
        String s2 = "b";
        String s3 = "a" + "b"; //直接量拼接:编译器可以直接优化结果为:"ab"
        String s4 = s1 + s2; //s1和s2为引用变量,编译器不能直接优化,内部采用StringBuilder进行处理,最终返回结果为new String("ab")
        String s5 = "ab";
        String s6 = s4.intern();
        //问
        System.out.println(s3 == s4); //false
        System.out.println(s3 == s5); //true
        System.out.println(s3 == s6); //true
        String x2 = new String("c") + new String("d"); // new String("cd")
        x2.intern();
        String x1 = "cd"; //
        //问,如果调换了[最后两行代码]的位置呢，如果是jdk1.6呢
        System. out.println(x1 == x2);
    }
}
